const app = getApp(),url = app.globalData.url;
Page({
  data: {
    seach:{
      current_page:0,
      page_size:10,
      title  :'',
    },
    listdata:[],
  },
  onLoad(options){
    console.log(options)
    var that = this
    that.setData({
      status:options.status,
      key:options.key,
      subTypeName:options.subTypeName
    })
    that.search()
  },

  search(){
    var that = this
    var listdata = that.data.listdata
    wx.showLoading({
      title: '加载中',
    })
    var status = that.data.status
    var key = that.data.key
    that.data.seach.title = key
    that.data.seach.current_page ++
    if(status == 4){//职场
      var urlapi = 'common/searchInquiryWorkplace'
    }else{//本地
      var urlapi = 'common/searchInquiryLocal'
    }
    
    wx.request({
      url:url+ urlapi,
      method: "GET",
      data:that.data.seach,
      success:function(res){
        console.log("搜索",res);
        var ret = res.data
        if(ret.code == 200){
          wx.hideLoading()
          // that.setData({listdata:ret.data.content})
          listdata=listdata.concat(ret.data.content)
            that.setData({listdata})
        }else{
          wx.hideLoading()
          that.setData({listdata:[]})
          wx.showToast({
            title: ret.msg,
            icon:'none'
          })
        }
      },
      fail:function(res){
        wx.hideLoading()
      }
    })
  },
    
  // 资讯详情
  newsdetail(e){
    var that = this
    let did = e.currentTarget.dataset.id
    let oneid = that.data.status
    wx.navigateTo({
      url: '/pages/newsdetail/newsdetail?id='+did + '&oneid='+oneid,
    })
  },
  onReachBottom: function () {
    console.log(1234)
    this.search()
  },
  onHide: function () {
    var that = this
    that.data.seach.current_page = 0
  },
  onUnload: function () {
    var that = this
    that.data.seach.current_page = 0
  },

})